package mk.jug.academy.service;

import mk.jug.academy.dao.AdministratorDAO;
import mk.jug.academy.model.Administrator;
import mk.jug.academy.testing.bdd.IntegrationBehavior;
import mk.jug.academy.testing.factory.AdministratorTestFactory;

import org.springframework.beans.factory.annotation.Autowired;

import com.googlecode.instinct.marker.annotate.Specification;
import com.googlecode.instinct.marker.annotate.Specification.SpecificationState;

/**
 * An integration test unit revolving around the behavior of an {@link Administrator}.
 *
 * @author Ice.Penov
 */
public class AdministratorFunctionality extends IntegrationBehavior {
	
	@Autowired private AdministratorDAO administratorDAO;
	@Autowired private AdministratorService administratorService;			
	
	@Specification(state = SpecificationState.COMPLETE)
	public void fetchExistingAdminByEmail() {
		Administrator admin = AdministratorTestFactory.createAdministrator();
		admin.setEmail("ipenov@gmail.com");
		//admins are usually created initially, from a startup db script.
		administratorDAO.save(admin);
		//expectations.
		Administrator administrator = administratorService.findByEmail("ipenov@gmail.com");
		Administrator shouldBeNull = administratorService.findByEmail("non@existent.com");
		expect.that(administrator).isEqualTo(admin);
		expect.that(shouldBeNull).isNull();
	}

}